﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbCompanyInformationTest and is intended
    ///     to contain all TmdbCompanyInformationTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbCompanyInformationTest
    {
        /// <summary>
        ///     A test for TmdbCompanyInformation Constructor
        /// </summary>
        [TestMethod]
        public void TmdbCompanyInformationConstructorTest()
        {
            var target = new TmdbCompanyInformation();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for Description
        /// </summary>
        [TestMethod]
        public void DescriptionTest()
        {
            var target = new TmdbCompanyInformation();
            string expected = Guid.NewGuid().ToString();
            target.Description = expected;
            string actual = target.Description;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Headquarter
        /// </summary>
        [TestMethod]
        public void HeadquarterTest()
        {
            var target = new TmdbCompanyInformation();
            string expected = Guid.NewGuid().ToString();
            target.Headquarter = expected;
            string actual = target.Headquarter;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Homepage
        /// </summary>
        [TestMethod]
        public void HomepageTest()
        {
            var target = new TmdbCompanyInformation();
            string expected = Guid.NewGuid().ToString();
            target.Homepage = expected;
            string actual = target.Homepage;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for ParentCompany
        /// </summary>
        [TestMethod]
        public void ParentCompanyTest()
        {
            var target = new TmdbCompanyInformation();
            var expected = new TmdbCompanyInformation();
            target.ParentCompany = expected;
            var actual = target.ParentCompany;
            Assert.AreSame( expected, actual );
        }

        /// <summary>
        ///     A test for Movies
        /// </summary>
        [TestMethod]
        public void MoviesTest()
        {
            var target = new TmdbCompanyInformation();
            var expected = new TmdbAdvancedMoviePreviewList();
            target.Movies = expected;
            var actual = target.Movies;
            Assert.AreSame(expected, actual);
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem( @"..\..\TestData\companyInfo_all.json.txt" )]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbCompanyInformation();
            var jsonContent = File.ReadAllText( "companyInfo_all.json.txt" );
            var actual = await target.DeserializeJson<TmdbCompanyInformation>( jsonContent );

            Assert.AreEqual(
                "Columbia Pictures Industries, Inc. (CPII) is an American film production and distribution company. Columbia Pictures now forms part of the Columbia TriStar Motion Picture Group, owned by Sony Pictures Entertainment, a subsidiary of the Japanese conglomerate Sony. It is one of the leading film companies in the world, a member of the so-called Big Six. It was one of the so-called Little Three among the eight major film studios of Hollywood's Golden Age.",
                actual.Description );
            Assert.AreEqual( null, actual.Headquarter );
            Assert.AreEqual( null, actual.Homepage );
            Assert.AreEqual( 5, actual.Id );
            Assert.AreEqual( "/mjUSfXXUhMiLAA1Zq1TfStNSoLR.png", actual.LogoPath );
            Assert.AreEqual( "Columbia Pictures", actual.Name );

            Assert.AreEqual( "Columbia TriStar", actual.ParentCompany.Name );
            Assert.AreEqual( 177, actual.ParentCompany.Id );
            Assert.AreEqual( null, actual.ParentCompany.LogoPath );

            Assert.AreEqual( 2, actual.Movies.PageNumber );
            Assert.AreEqual( 256, actual.Movies.TotalResults );
            Assert.AreEqual( 13, actual.Movies.TotalPages );

            Assert.AreEqual( false, actual.Movies.Movies[ 0 ].IsAdult );
            Assert.AreEqual( null, actual.Movies.Movies[ 0 ].BackdropPath );
            Assert.AreEqual( 97020, actual.Movies.Movies[ 0 ].Id );
            Assert.AreEqual( "RoboCop", actual.Movies.Movies[ 0 ].OriginalTitle );
            Assert.AreEqual( "2014-02-07", actual.Movies.Movies[ 0 ].ReleaseDate );
            Assert.AreEqual( "/ciKJ86leibh99EYZjjsP8PszCJ7.jpg", actual.Movies.Movies[ 0 ].PosterPath );
            Assert.AreEqual( 1.4736, actual.Movies.Movies[ 0 ].Popularity );
            Assert.AreEqual( "RoboCop", actual.Movies.Movies[ 0 ].Title );
            Assert.AreEqual( 10.0, actual.Movies.Movies[ 0 ].VoteAverage );
            Assert.AreEqual( 1, actual.Movies.Movies[ 0 ].VoteCount );

            Assert.AreEqual(false, actual.Movies.Movies[1].IsAdult);
            Assert.AreEqual( "/hWTVuoTwGOgcctaNU5EhCQKDfwZ.jpg", actual.Movies.Movies[ 1 ].BackdropPath );
            Assert.AreEqual( 8769, actual.Movies.Movies[ 1 ].Id );
            Assert.AreEqual( "Christine", actual.Movies.Movies[ 1 ].OriginalTitle );
            Assert.AreEqual( "1983-12-09", actual.Movies.Movies[ 1 ].ReleaseDate );
            Assert.AreEqual( "/dfgA9b0eK0Dqmyf8X9X0qhvpx6z.jpg", actual.Movies.Movies[ 1 ].PosterPath );
            Assert.AreEqual(2.09475968527999, actual.Movies.Movies[1].Popularity);
            Assert.AreEqual( "Christine", actual.Movies.Movies[ 1 ].Title );
            Assert.AreEqual( 7.9, actual.Movies.Movies[ 1 ].VoteAverage );
            Assert.AreEqual( 19, actual.Movies.Movies[ 1 ].VoteCount );
        }
    }
}